package offer;

import java.util.ArrayList;
import java.util.List;

public class offerII_0064 {
    class MagicDictionary {

        /** Initialize your data structure here. */
        List<String> list;
        int len;
        public MagicDictionary() {
            list=new ArrayList<>();
            len=0;
        }

        public void buildDict(String[] dictionary) {
            len+=dictionary.length;
            for(int i=0;i<len;++i){
                list.add(dictionary[i]);
            }
        }

        public boolean search(String searchWord) {
            int strlen=searchWord.length();
            for(int i=0;i<len;++i){
                boolean flag=true;
                if(list.get(i).length()==strlen){
                    for(int j=0;j<strlen;++j){
                        if(searchWord.charAt(j)!=list.get(i).charAt(j)){
                            if(flag) flag=false;
                            else break;
                        }
                        if(!flag&&j==strlen-1) return true;
                    }
                }
            }
            return false;
        }
    }
}
